VERSION 2.00 Begin Form Form1 BackColor = &H00000000& BorderStyle = 1 'Fixed Single Caption = "MONTOR System Monitor" ClientHeight = 5145 ClientLeft = 15 ClientTop = 825 ClientWidth = 9150 ForeColor = &H0000FFFF& Height = 6075 Icon = 0 Left = -45 LinkTopic = "Form1" MaxButton = 0 'False ScaleHeight = 5145 ScaleWidth = 9150 Top = -45 Width = 9270 Begin PictureBox GaugeMain AutoSize = -1 'True BackColor = &H00C0C0C0& BorderStyle = 0 'None FillStyle = 0 'Solid ForeColor = &H0000FFFF& Height = 3225 Index = 0 Left = 1680 Picture = MONTOR.FRX:0000 ScaleHeight = 3225 ScaleWidth = 720 TabIndex = 0 Tag = "100" Top = 840 Width = 720 Begin Image WarnLevPtr DragIcon = MONTOR.FRX:14A2 DragMode = 1 'Automatic Height = 165 Index = 0 Left = 420 Picture = MONTOR.FRX:15EC Top = 3000 Width = 300 End Begin Image CurrValPtr Height = 165 Index = 0 Left = 0 Picture = MONTOR.FRX:16EA Top = 0 Width = 300 End End Begin PictureBox GaugeMain AutoSize = -1 'True BackColor = &H00C0C0C0& BorderStyle = 0 'None FillStyle = 0 'Solid ForeColor = &H0000FFFF& Height = 3225 Index = 7 Left = 8280 ScaleHeight = 3225 ScaleWidth = 750 TabIndex = 7 TabStop = 0 'False Tag = "100" Top = 840 Width = 750 Begin Image CurrValPtr Height = 165 Index = 7 Left = 0 Top = 0 Width = 300 End Begin Image WarnLevPtr DragIcon = MONTOR.FRX:17E8 DragMode = 1 'Automatic Height = 165 Index = 7 Left = 420 Top = 3000 Width = 300 End End Begin PictureBox GaugeMain AutoSize = -1 'True BackColor = &H00C0C0C0& BorderStyle = 0 'None FillStyle = 0 'Solid ForeColor = &H0000FFFF& Height = 3225 Index = 6 Left = 7320 ScaleHeight = 3225 ScaleWidth = 750 TabIndex = 6 TabStop = 0 'False Tag = "100" Top = 840 Width = 750 Begin Image CurrValPtr Height = 165 Index = 6 Left = 0 Top = 0 Width = 300 End Begin Image WarnLevPtr DragIcon = MONTOR.FRX:1932 DragMode = 1 'Automatic Height = 165 Index = 6 Left = 420 Top = 3000 Width = 300 End End Begin PictureBox GaugeMain AutoSize = -1 'True BackColor = &H00C0C0C0& BorderStyle = 0 'None FillStyle = 0 'Solid ForeColor = &H0000FFFF& Height = 3225 Index = 5 Left = 6360 ScaleHeight = 3225 ScaleWidth = 750 TabIndex = 5 TabStop = 0 'False Tag = "100" Top = 840 Width = 750 Begin Image CurrValPtr Height = 165 Index = 5 Left = 0 Top = 0 Width = 300 End Begin Image WarnLevPtr DragIcon = MONTOR.FRX:1A7C DragMode = 1 'Automatic Height = 165 Index = 5 Left = 420 Top = 3000 Width = 300 End End Begin PictureBox GaugeMain AutoSize = -1 'True BackColor = &H00C0C0C0& BorderStyle = 0 'None FillStyle = 0 'Solid ForeColor = &H0000FFFF& Height = 3225 Index = 4 Left = 5400 ScaleHeight = 3225 ScaleWidth = 750 TabIndex = 4 TabStop = 0 'False Tag = "100" Top = 840 Width = 750 Begin Image CurrValPtr Height = 165 Index = 4 Left = 0 Top = 0 Width = 300 End Begin Image WarnLevPtr DragIcon = MONTOR.FRX:1BC6 DragMode = 1 'Automatic Height = 165 Index = 4 Left = 420 Top = 3000 Width = 300 End End Begin PictureBox GaugeMain AutoSize = -1 'True BackColor = &H00C0C0C0& BorderStyle = 0 'None FillStyle = 0 'Solid ForeColor = &H0000FFFF& Height = 3225 Index = 3 Left = 4440 ScaleHeight = 3225 ScaleWidth = 750 TabIndex = 3 Tag = "100" Top = 840 Width = 750 Begin Image CurrValPtr Height = 165 Index = 3 Left = 0 Top = 0 Width = 300 End Begin Image WarnLevPtr DragIcon = MONTOR.FRX:1D10 DragMode = 1 'Automatic Height = 165 Index = 3 Left = 420 Top = 3000 Width = 300 End End Begin Timer Timer1 Interval = 2000 Left = 120 Top = 3480 End Begin PictureBox GaugeMain AutoSize = -1 'True BackColor = &H00C0C0C0& BorderStyle = 0 'None FillStyle = 0 'Solid ForeColor = &H0000FFFF& Height = 3225 Index = 2 Left = 3480 ScaleHeight = 3225 ScaleWidth = 750 TabIndex = 2 Tag = "100" Top = 840 Width = 750 Begin Image CurrValPtr Height = 165 Index = 2 Left = 0 Top = 0 Width = 300 End Begin Image WarnLevPtr DragIcon = MONTOR.FRX:1E5A DragMode = 1 'Automatic Height = 165 Index = 2 Left = 420 Top = 3000 Width = 300 End End Begin PictureBox GaugeMain AutoSize = -1 'True BackColor = &H00C0C0C0& BorderStyle = 0 'None FillStyle = 0 'Solid ForeColor = &H0000FFFF& Height = 3225 Index = 1 Left = 2520 ScaleHeight = 3225 ScaleWidth = 750 TabIndex = 1 Tag = "100" Top = 840 Width = 750 Begin Image WarnLevPtr DragIcon = MONTOR.FRX:1FA4 DragMode = 1 'Automatic Height = 165 Index = 1 Left = 420 Top = 3000 Width = 300 End Begin Image CurrValPtr Height = 165 Index = 1 Left = 0 Top = 0 Width = 300 End End Begin Shape Circ BackColor = &H00000080& BackStyle = 1 'Opaque Height = 735 Index = 1 Left = 480 Shape = 3 'Circle Top = 2760 Width = 735 End Begin Shape Circ BackColor = &H000000FF& BackStyle = 1 'Opaque Height = 735 Index = 0 Left = 480 Shape = 3 'Circle Top = 1320 Width = 735 End Begin Label RowLabel Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "Warn At:" ForeColor = &H00FFFFFF& Height = 255 Index = 4 Left = 120 TabIndex = 46 Top = 4800 Width = 1335 End Begin Label RowLabel Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "Percent Free:" ForeColor = &H00FFFFFF& Height = 255 Index = 3 Left = 120 TabIndex = 45 Top = 4440 Width = 1335 End Begin Label RowLabel Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "Free:" ForeColor = &H00FFFFFF& Height = 255 Index = 2 Left = 120 TabIndex = 44 Top = 4080 Width = 1335 End Begin Label RowLabel Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "Max Value:" ForeColor = &H00FFFFFF& Height = 255 Index = 1 Left = 120 TabIndex = 43 Top = 480 Width = 1335 End Begin Label RowLabel Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "Resource:" ForeColor = &H00FFFFFF& Height = 255 Index = 0 Left = 120 TabIndex = 42 Top = 120 Width = 1335 End Begin Label CurrValLab Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "0k" FontBold = -1 'True FontItalic = 0 'False FontName = "Arial" FontSize = 8.25 FontStrikethru = 0 'False FontUnderline = 0 'False ForeColor = &H0000FFFF& Height = 255 Index = 7 Left = 8280 TabIndex = 29 Top = 4080 Width = 735 End Begin Label CurrValLab Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "0k" FontBold = -1 'True FontItalic = 0 'False FontName = "Arial" FontSize = 8.25 FontStrikethru = 0 'False FontUnderline = 0 'False ForeColor = &H0000FFFF& Height = 255 Index = 6 Left = 7320 TabIndex = 30 Top = 4080 Width = 735 End Begin Label CurrValLab Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "0k" FontBold = -1 'True FontItalic = 0 'False FontName = "Arial" FontSize = 8.25 FontStrikethru = 0 'False FontUnderline = 0 'False ForeColor = &H0000FFFF& Height = 255 Index = 5 Left = 6360 TabIndex = 31 Top = 4080 Width = 735 End Begin Label CurrValLab Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "0k" FontBold = -1 'True FontItalic = 0 'False FontName = "Arial" FontSize = 8.25 FontStrikethru = 0 'False FontUnderline = 0 'False ForeColor = &H0000FFFF& Height = 255 Index = 4 Left = 5400 TabIndex = 41 Top = 4080 Width = 735 End Begin Label CurrValLab Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "0k" FontBold = -1 'True FontItalic = 0 'False FontName = "Arial" FontSize = 8.25 FontStrikethru = 0 'False FontUnderline = 0 'False ForeColor = &H0000FFFF& Height = 255 Index = 3 Left = 4440 TabIndex = 40 Top = 4080 Width = 735 End Begin Label PercentLab Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "0%" ForeColor = &H0000FFFF& Height = 255 Index = 7 Left = 8280 TabIndex = 36 Top = 4440 Width = 735 End Begin Label HeadingLab Alignment = 2 'Center BackColor = &H00000000& Caption = "Drive F:" ForeColor = &H0000FFFF& Height = 255 Index = 7 Left = 8280 TabIndex = 37 Top = 120 Width = 735 End Begin Label WarnLabel Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "20%" ForeColor = &H0000FFFF& Height = 255 Index = 7 Left = 8280 TabIndex = 38 Top = 4800 Width = 735 End Begin Label MaxValueLab Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "999,999k" FontBold = -1 'True FontItalic = 0 'False FontName = "Arial" FontSize = 8.25 FontStrikethru = 0 'False FontUnderline = 0 'False ForeColor = &H0000FFFF& Height = 255 Index = 7 Left = 8280 TabIndex = 39 Top = 480 Width = 735 End Begin Label MaxValueLab Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "999,999k" FontBold = -1 'True FontItalic = 0 'False FontName = "Arial" FontSize = 8.25 FontStrikethru = 0 'False FontUnderline = 0 'False ForeColor = &H0000FFFF& Height = 255 Index = 6 Left = 7320 TabIndex = 35 Top = 480 Width = 735 End Begin Label MaxValueLab Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "999,999k" FontBold = -1 'True FontItalic = 0 'False FontName = "Arial" FontSize = 8.25 FontStrikethru = 0 'False FontUnderline = 0 'False ForeColor = &H0000FFFF& Height = 255 Index = 5 Left = 6360 TabIndex = 34 Top = 480 Width = 735 End Begin Label MaxValueLab Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "999,999k" FontBold = -1 'True FontItalic = 0 'False FontName = "Arial" FontSize = 8.25 FontStrikethru = 0 'False FontUnderline = 0 'False ForeColor = &H0000FFFF& Height = 255 Index = 4 Left = 5400 TabIndex = 33 Top = 480 Width = 735 End Begin Label MaxValueLab Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "999,999k" FontBold = -1 'True FontItalic = 0 'False FontName = "Arial" FontSize = 8.25 FontStrikethru = 0 'False FontUnderline = 0 'False ForeColor = &H0000FFFF& Height = 255 Index = 3 Left = 4440 TabIndex = 32 Top = 480 Width = 735 End Begin Label WarnLabel Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "20%" ForeColor = &H0000FFFF& Height = 255 Index = 6 Left = 7320 TabIndex = 28 Top = 4800 Width = 735 End Begin Label HeadingLab Alignment = 2 'Center BackColor = &H00000000& Caption = "Drive E:" ForeColor = &H0000FFFF& Height = 255 Index = 6 Left = 7320 TabIndex = 27 Top = 120 Width = 735 End Begin Label PercentLab Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "0%" ForeColor = &H0000FFFF& Height = 255 Index = 6 Left = 7320 TabIndex = 26 Top = 4440 Width = 735 End Begin Label WarnLabel Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "20%" ForeColor = &H0000FFFF& Height = 255 Index = 5 Left = 6360 TabIndex = 25 Top = 4800 Width = 735 End Begin Label HeadingLab Alignment = 2 'Center BackColor = &H00000000& Caption = "Drive D:" ForeColor = &H0000FFFF& Height = 255 Index = 5 Left = 6360 TabIndex = 24 Top = 120 Width = 735 End Begin Label PercentLab Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "0%" ForeColor = &H0000FFFF& Height = 255 Index = 5 Left = 6360 TabIndex = 23 Top = 4440 Width = 735 End Begin Label WarnLabel Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "20%" ForeColor = &H0000FFFF& Height = 255 Index = 4 Left = 5400 TabIndex = 22 Top = 4800 Width = 735 End Begin Label HeadingLab Alignment = 2 'Center BackColor = &H00000000& Caption = "Drive C:" ForeColor = &H0000FFFF& Height = 255 Index = 4 Left = 5400 TabIndex = 21 Top = 120 Width = 735 End Begin Label PercentLab Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "0%" ForeColor = &H0000FFFF& Height = 255 Index = 4 Left = 5400 TabIndex = 20 Top = 4440 Width = 735 End Begin Label PercentLab Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "0%" ForeColor = &H0000FFFF& Height = 255 Index = 3 Left = 4440 TabIndex = 19 Top = 4440 Width = 735 End Begin Label HeadingLab Alignment = 2 'Center BackColor = &H00000000& Caption = "Memory" ForeColor = &H0000FFFF& Height = 255 Index = 3 Left = 4440 TabIndex = 18 Top = 120 Width = 735 End Begin Label WarnLabel Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "20%" ForeColor = &H0000FFFF& Height = 255 Index = 3 Left = 4440 TabIndex = 17 Top = 4800 Width = 735 End Begin Label WarnLabel Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "20%" ForeColor = &H0000FFFF& Height = 255 Index = 2 Left = 3480 TabIndex = 16 Top = 4800 Width = 735 End Begin Label WarnLabel Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "20%" ForeColor = &H0000FFFF& Height = 255 Index = 1 Left = 2520 TabIndex = 15 Top = 4800 Width = 735 End Begin Label WarnLabel Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "20%" ForeColor = &H0000FFFF& Height = 255 Index = 0 Left = 1560 TabIndex = 14 Top = 4800 Width = 735 End Begin Label HeadingLab Alignment = 2 'Center BackColor = &H00000000& Caption = "User" ForeColor = &H0000FFFF& Height = 255 Index = 2 Left = 3480 TabIndex = 13 Top = 120 Width = 735 End Begin Label HeadingLab Alignment = 2 'Center BackColor = &H00000000& Caption = "GDI" ForeColor = &H0000FFFF& Height = 255 Index = 1 Left = 2520 TabIndex = 12 Top = 120 Width = 735 End Begin Label HeadingLab Alignment = 2 'Center BackColor = &H00000000& Caption = "System" ForeColor = &H0000FFFF& Height = 255 Index = 0 Left = 1560 TabIndex = 11 Top = 120 Width = 735 End Begin Label PercentLab Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "0%" ForeColor = &H0000FFFF& Height = 255 Index = 2 Left = 3480 TabIndex = 10 Top = 4440 Width = 735 End Begin Label PercentLab Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "0%" ForeColor = &H0000FFFF& Height = 255 Index = 1 Left = 2520 TabIndex = 9 Top = 4440 Width = 735 End Begin Label PercentLab Alignment = 1 'Right Justify BackColor = &H00000000& Caption = "0%" ForeColor = &H0000FFFF& Height = 255 Index = 0 Left = 1560 TabIndex = 8 Top = 4440 Width = 735 End Begin Menu mnu_Main Caption = "&File" Index = 0 Begin Menu mnu_File Caption = "E&xit" Index = 0 End End Begin Menu mnu_Main Caption = "&Options" Index = 1 Begin Menu mnu_Options Caption = "&Jiggle pointers" Checked = -1 'True HelpContextID = 6 Index = 0 End Begin Menu mnu_Options Caption = "&Save Settings On Exit" Checked = -1 'True HelpContextID = 7 Index = 1 End End Begin Menu mnu_Main Caption = "&Icon Display" Index = 2 Begin Menu mnu_Icon Caption = "&System" HelpContextID = 1 Index = 0 End Begin Menu mnu_Icon Caption = "&GDI" HelpContextID = 1 Index = 1 End Begin Menu mnu_Icon Caption = "&User" HelpContextID = 1 Index = 2 End Begin Menu mnu_Icon Caption = "&Memory" HelpContextID = 2 Index = 3 End End Begin Menu mnu_Main Caption = "&Help" Index = 4 Begin Menu mnu_Help Caption = "&Contents" Index = 0 End Begin Menu mnu_Help Caption = "&Search for Help On..." Index = 1 End Begin Menu mnu_Help Caption = "&How to Use Help" Index = 2 End Begin Menu mnu_Help Caption = "-" Index = 3 End Begin Menu mnu_Help Caption = "&About Montor..." Index = 4 End End End Option Explicit Dim TopAdj% ' distance of 100% mark from top of gauge Dim GHeight! ' height of gauge - used in several routines Dim WhichIcon% ' Tells which resource to show when iconic Dim LineL%, LineR% ' Range of a click on gauge line Sub ChangeWarn (ByVal Index%, ByVal Change%) ' Move a warning level pointer up or down by specified percent WarnLevPtr(Index).Tag = WarnLevPtr(Index).Tag + Change If WarnLevPtr(Index).Tag > 100 Then WarnLevPtr(Index).Tag = 100 If WarnLevPtr(Index).Tag < 0 Then WarnLevPtr(Index).Tag = 0 ' Place the pointer and adjust the labels PlaceWarnPtr Index End Sub Sub Form_Load () ' If a previous instance is running, activate it instead Dim SaveTitle As String * 40 If App.PrevInstance Then SaveTitle$ = App.Title App.Title = "... duplicate instance." Form1.Caption = "... duplicate instance." AppActivate SaveTitle$ SendKeys "% R", True End End If ' Initialize two variables used in calculating pointer positions. ' Gauge line starts and ends 7 pixels from top/bottom of bitmap. TopAdj = 7 * Screen.TwipsPerPixelY GHeight = 200 * Screen.TwipsPerPixelY ' Include gauges for up to four fixed disks. Use GetDriveType to ' check each possible drive letter - only monitor those whose type ' is DRIVE_FIXED ActualGauges = 4 Dim N%, Disk As String * 2 N = 0 Do While (N < 26) And (ActualGauges < NumGauges) If GetDriveType(N) = DRIVE_FIXED Then GaugeMain(ActualGauges).TabStop = True Disk = Chr$(N + 65) + ":" HeadingLab(ActualGauges).Caption = "Drive " + Disk ' Tag for HeadingLab is disk NUMBER for disk size functions HeadingLab(ActualGauges).Tag = N + 1 Load Form1.mnu_Icon(ActualGauges) Form1.mnu_Icon(ActualGauges).Caption = "Drive &" + Disk Form1.mnu_Icon(ActualGauges).Visible = True Form1.mnu_Icon(ActualGauges).HelpContextID = 3 ActualGauges = ActualGauges + 1 End If N = N + 1 Loop ' Shrink the form to chop off any unused drive gauges Width = GaugeMain(ActualGauges - 1).Left Width = Width + GaugeMain(ActualGauges - 1).Width Width = Width + (16 * Screen.TwipsPerPixelX) LoadFromIni Randomize ' To save EXE size, we store each picture ONCE in the EXE and ' copy it to the other elements of the same control array. Dim X% X = GaugeMain(0).Width - WarnLevPtr(0).Width For N = 0 To ActualGauges - 1 CurrValPtr(N).Picture = CurrValPtr(0).Picture WarnLevPtr(N).Picture = WarnLevPtr(0).Picture WarnLevPtr(N).DragIcon = WarnLevPtr(0).DragIcon GaugeMain(N).Picture = GaugeMain(0).Picture PlaceWarnPtr N Next N ' Get the total system memory Dim mmi As tagMemManInfo mmi.Size = MMIsize Dim Success% Success = MemManInfo(mmi) GaugeMain(3).Tag = mmi.TotalPages + mmi.SwapFilePages GaugeMain(3).Tag = GaugeMain(3).Tag * mmi.PageSize MaxValueLab(3).Caption = MegaOrKilo(GaugeMain(3).Tag) ' Get the size of each fixed drive For N = 4 To ActualGauges - 1 GaugeMain(N).Tag = GetDiskSize(HeadingLab(N).Tag) MaxValueLab(N).Caption = MegaOrKilo(GaugeMain(N).Tag) Next N ' Set left and right boundaries of the area on each gauge that will ' be accepted as a click ON the gauge's vertical line. LineL = GaugeMain(0).Width \ 2 - 60 LineR = LineL + 120 End Sub Sub Form_QueryUnload (Cancel As Integer, UnloadMode As Integer) SaveToIni Cancel = 0 End Sub Sub Form_Resize () ' If iconic, indicate which resource is being displayed If WindowState = 1 Then Caption = "Monitor " + HeadingLab(WhichIcon).Caption Else Caption = "System Monitor" End If End Sub Sub GaugeMain_DragDrop (Index As Integer, Source As Control, X As Single, Y As Single) ' Don't allow dropping onto a different gauge! If Source.Index <> Index Then Exit Sub ' Adjust position to stay within 0-100% If Y > TopAdj + GHeight Then Y = TopAdj + GHeight If Y < TopAdj Then Y = TopAdj ' Calculate new percent based on new position Source.Tag = (TopAdj + GHeight - Y) * 100 \ GHeight ' Place the pointer and adjust the labels PlaceWarnPtr Index End Sub Sub GaugeMain_GotFocus (Index As Integer) ' Indicate the selected gauge by highlighting its warn label WarnLabel(Index).BackColor = &H808080 End Sub Sub GaugeMain_KeyUp (Index As Integer, KeyCode As Integer, Shift As Integer) ' When it receives an up or downarrow, the Picture Box tweaks ' the warning level up or down by one percent. When ' it receives PgUp or PgDn, it tweaks the level by five percent Select Case KeyCode Case KEY_UP ChangeWarn ActiveControl.Index, 1 Case KEY_DOWN ChangeWarn ActiveControl.Index, -1 Case KEY_PRIOR ' PgUp ChangeWarn ActiveControl.Index, 5 Case KEY_NEXT ' PgDn ChangeWarn ActiveControl.Index, -5 End Select End Sub Sub GaugeMain_LostFocus (Index As Integer) ' Indicate the unselected gauge by unhighlighting its warn label WarnLabel(Index).BackColor = 0 End Sub Sub GaugeMain_MouseUp (Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) ' If the user clicked on the line in the middle of the gauge... If (X >= LineL) And (X <= LineR) Then ' If they clicked above warning pointer, raise it, else lower it Dim Locat! Locat = (TopAdj + GHeight - Y) * 100 \ GHeight If Locat > WarnLevPtr(Index).Tag Then ChangeWarn Index, 1 Else ChangeWarn Index, -1 End If End If End Sub Sub HeadingLab_Click (Index As Integer) ' Click on label at gauge top to display that resource when iconic. SelectIconReport (Index) End Sub Sub LoadFromIni () ' Load program options from MONTOR.INI mnu_Options(0).Checked = GetPrivateProfileInt("Options", "Jiggle Pointers", True, "MONTOR.INI") mnu_Options(1).Checked = GetPrivateProfileInt("Options", "Save Settings", True, "MONTOR.INI") Dim IconRpt% IconRpt = GetPrivateProfileInt("Icon Display", "Icon", 0, "MONTOR.INI") SelectIconReport (IconRpt) ' Get warning level for each gauge, or default of 20% Dim N% For N = 0 To ActualGauges - 1 WarnLevPtr(N).Tag = GetPrivateProfileInt("Warning Levels", "Gauge" + Str$(N), 20, "MONTOR.INI") Next N End Sub Function MegaOrKilo$ (ByVal Amount&) ' Display below 1 million kilobytes as k, greater as M Const Kilo% = &H400 Const Mega& = &H100000 If Amount >= 1000000 * Kilo Then MegaOrKilo = Format$(Amount \ Mega, "###,###,###") + "M" Else MegaOrKilo = Format$(Amount \ Kilo, "###,###") + "k" End If End Function Sub mnu_File_Click (Index As Integer) ' Note that form2 (About box) and form3 (warning dialog) ' are unloaded after each use. Unload Form1 End Sub Sub mnu_Help_Click (Index As Integer) ' WinHelp and WinHelpByNum are declared in MONTOR.BAS. VB programs ' have automatic context-sensitive help, but they need these API ' functions for menu-selected help. Dim Success% Select Case Index Case 0 Success = WinHelpByNum(Form1.hWnd, App.HelpFile, HELP_CONTENTS, 0) Case 1 Success = WinHelp(Form1.hWnd, App.HelpFile, HELP_PARTIALKEY, "") Case 2 Success = WinHelpByNum(Form1.hWnd, App.HelpFile, HELP_HELPONHELP, 0) Case 4 Form2.Show MODAL Unload Form2 End Select End Sub Sub mnu_Icon_Click (Index As Integer) ' Select name from icon menu to display that resource when iconic. SelectIconReport (Index) End Sub Sub mnu_Options_Click (Index As Integer) ' Information about whether the two Options menu items are checked ' is simply stored in Checked property of the menu items. mnu_Options(Index).Checked = Not mnu_Options(Index).Checked End Sub Sub PlaceWarnPtr (ByVal Index%) ' The warning level pointer's tag contains the new percent - now ' adjust the labels and place the pointer to match that percent. ' Adjust the Warn At caption WarnLabel(Index).Caption = Str$(WarnLevPtr(Index).Tag) + "%" ' The gauge is exactly 200 pixels high Dim NewY% ' Set NewY to the *pixel* height corresponding to the percentage NewY = ((98 - WarnLevPtr(Index).Tag) * 2) - 1 ' Convert NewY to twips (VB's unit of screen measurement) NewY = NewY * Screen.TwipsPerPixelY ' Adjust to start at the top of the gauge line NewY = NewY + TopAdj WarnLevPtr(Index).Move WarnLevPtr(Index).Left, NewY WarnLabel(Index).Tag = False End Sub Sub SaveToIni () ' Write Save Settings option to MONTOR.INI; write the rest of the ' options only if Save Settings is TRUE Dim Success% Success% = WritePrivateProfileString("Options", "Save Settings", mnu_Options(1).Checked, "MONTOR.INI") If mnu_Options(1).Checked Then Success% = WritePrivateProfileString("Options", "Jiggle Pointers", mnu_Options(0).Checked, "MONTOR.INI") Success% = WritePrivateProfileString("Icon Display", "Icon", Str$(WhichIcon), "MONTOR.INI") Dim N% For N = 0 To ActualGauges - 1 Success% = WritePrivateProfileString("Warning Levels", "Gauge" + Str$(N), WarnLevPtr(N).Tag, "MONTOR.INI") Next N End If End Sub Sub SelectIconReport (ByVal Index%) ' Un-check old selected item & set its label's background to black mnu_Icon(WhichIcon).Checked = False HeadingLab(WhichIcon).BackColor = 0 ' Check new selected item & set its label's background to gray mnu_Icon(Index).Checked = True HeadingLab(Index).BackColor = &H808080 WhichIcon = Index End Sub Sub Timer1_Timer () ' This method is called about every two seconds - it updates all of ' the gauges and warns if any have dropped below the minimum. If ' MONTOR is iconic, it draws the icon. ' Set current values for the system resource gauges Dim shi As TagSysHeapInfo shi.Size = SHIsize Dim Success% Success = SystemHeapInfo(shi) CurrValPtr(2).Tag = shi.UserFreePercent CurrValPtr(1).Tag = shi.GDIFreePercent If shi.UserFreePercent < shi.GDIFreePercent Then CurrValPtr(0).Tag = shi.UserFreePercent Else CurrValPtr(0).Tag = shi.GDIFreePercent End If ' Set and display current value for the memory gauge CurrValPtr(3).Tag = GetFreeSpace(0) CurrValLab(3).Caption = MegaOrKilo(CurrValPtr(3).Tag) ' Set and display current value for disk space gauges Dim N% For N = 4 To ActualGauges - 1 CurrValPtr(N).Tag = GetDiskFree(HeadingLab(N).Tag) CurrValLab(N).Caption = MegaOrKilo(CurrValPtr(N).Tag) Next N ' Redisplay the pointers Dim Locat!, Percent! Dim NewCVY% For N = 0 To ActualGauges - 1 ' Calculate the current percentage NewCVY = (100 * CurrValPtr(N).Tag) / GaugeMain(N).Tag PercentLab(N).Caption = Str$(NewCVY) + "%" NewCVY = ((98 - NewCVY) * 2) - 1 NewCVY = NewCVY * Screen.TwipsPerPixelY NewCVY = NewCVY + TopAdj CurrValPtr(N).Move 0, NewCVY Next N ' If the "Jiggle Pointers" option is checked... If mnu_Options(0).Checked Then ' Blink the "pulse" circles Dim TempCol& TempCol = Circ(0).BackColor Circ(0).BackColor = Circ(1).BackColor Circ(1).BackColor = TempCol ' Jiggle the pointers Dim NewY% For N = 0 To ActualGauges - 1 Select Case Rnd Case 0 To .2 NewY = CurrValPtr(N).Top + Screen.TwipsPerPixelY CurrValPtr(N).Move CurrValPtr(N).Left, NewY Case .2 To .4 NewY = CurrValPtr(N).Top - Screen.TwipsPerPixelY CurrValPtr(N).Move CurrValPtr(N).Left, NewY End Select Next N End If ' Check if any warnings are necessary For N = 0 To ActualGauges - 1 Percent = (CurrValPtr(N).Tag * 100) / GaugeMain(N).Tag If Percent < WarnLevPtr(N).Tag Then If Not WarnLabel(N).Tag Then Select Case N Case 0 To 2 ' Normally you would assign WnTx's value using one long ' program line. Here it's built up gradually, so as to ' make it easier to publish the source code. WnTx = "Free " + HeadingLab(N).Caption + " resources have" WnTx = WnTx + " dropped below" + Str$(WarnLevPtr(N).Tag) WnTx = WnTx + "%." + Chr$(13) + Chr$(13) + "Even if you " WnTx = WnTx + "have plenty of memory free, you will not " WnTx = WnTx + "be able to run many more programs. " WnTx = WnTx + "Consider closing one or more programs." WarnHelp = 1 Case 3 WnTx = "Free memory has dropped below" WnTx = WnTx + Str$(WarnLevPtr(N).Tag) + "%." + Chr$(13) WnTx = WnTx + Chr$(13) + "Consider closing one or more " WnTx = WnTx + "programs." WarnHelp = 2 Case 4 To ActualGauges WnTx = "Free disk space on " + HeadingLab(N) + " has " WnTx = WnTx + "dropped below" + Str$(WarnLevPtr(N).Tag) WnTx = WnTx + "%." + Chr$(13) + Chr$(13) + "Consider " WnTx = WnTx + "using File Manager to delete any files " WnTx = WnTx + "that are no longer needed." WarnHelp = 3 End Select MessageBeep MB_ICONSTOP Form3.Show MODAL Unload Form3 WarnLabel(N).Tag = True End If Else WarnLabel(N).Tag = False End If Next N ' If MONTOR is iconic, draw the icon If WindowState = 1 Then ' fill whole area with black Line (0, 0)-(ScaleWidth, ScaleHeight), 0, BF ' draw gauge-line near right side Line (ScaleWidth - 60, 0)-(ScaleWidth - 60, ScaleHeight) ' set location for writing percent value CurrentX = 2 * Screen.TwipsPerPixelX Percent = (CurrValPtr(WhichIcon).Tag) / GaugeMain(WhichIcon).Tag ' Set Y position to avoid printing on light/dark boundary If Percent < .5 Then CurrentY = Screen.TwipsPerPixelY Else CurrentY = ScaleHeight \ 2 End If Print PercentLab(WhichIcon).Caption ' XOR the portion corresponding to free percentage DrawMode = 7 Dim Y! Y = (1 - Percent) * (ScaleHeight)' - (2 * TopAdj)) Line (0, Y)-(ScaleWidth, ScaleHeight), &HFFFFFF, BF DrawMode = 13 End If End Sub Sub WarnLabel_Click (Index As Integer) GaugeMain(Index).SetFocus End Sub